Component({
  data: {
    formData: {
      switchChecked: false,
      radio: "1",
      checkbox: ["b"],
      inputValue: "",
    },
  },
  methods: {
    formSubmit(e: WechatMiniprogram.CustomEvent) {
      console.log("form发生了submit事件，携带数据为：", this.data.formData);
    },
    formReset(e: WechatMiniprogram.CustomEvent) {
      console.log("form发生了reset事件，携带数据为：", {
        switchChecked: false,
        radio: "1",
        checkbox: ["b"],
        inputValue: "",
      });
      this.setData({
        formData: {
          switchChecked: false,
          radio: "1",
          checkbox: ["b"],
          inputValue: "",
        },
      });
    },
    onSwitchChange(event: WechatMiniprogram.CustomEvent) {
      const field = event.currentTarget.dataset.field as string;
      this.setData({ [field]: event.detail });
    },
    onCheckboxChange(event: WechatMiniprogram.CustomEvent) {
      const field = event.currentTarget.dataset.field as string;
      this.setData({ [field]: event.detail });
    },
    onRadioChange(event: WechatMiniprogram.CustomEvent) {
      const field = event.currentTarget.dataset.field as string;
      this.setData({ [field]: event.detail });
    },
    onInputChange(event: WechatMiniprogram.CustomEvent) {
      const field = event.currentTarget.dataset.field as string;
      this.setData({ [field]: event.detail });
    },
  },
});
